public class MyScanner
{
    private String str;
    private int i;
    private boolean lastSuccess;

    public MyScanner()
    {
        str="";
        i=0;
        lastSuccess=true;
    }
    public MyScanner(MyScanner sc)
    {
        str=sc.str;
        i=sc.i;
        lastSuccess=sc.lastSuccess;
    }
    public MyScanner(final String s)
    {
        str=s;
        i=0;
        lastSuccess=true;
    }
    public void setString(final String s)
    {
        str=s;
        i=0;
        lastSuccess=true;
    }
    public void reset()
    {
        i=0;
        lastSuccess=true;
    }
    public boolean ifLastSuccess()
    {
        return lastSuccess;
    }
    public int nextUnsignedInt()
    {
        return nextUnsignedInt(true);
    }
    public char nextChar()
    {
        return i<str.length()?str.charAt(i):0;
    }

    public int nextInt()
    {
        return nextInt(true);
    }
    public double nextDouble()
    {
        return nextDouble(true);
    }
    public double nextScience()
    {
        return nextScience(true);
    }
    public int nextUnsignedInt(boolean ignoreFrontSpace)
    {
        char c=0;
        int x=0, n=str.length();
        if(ignoreFrontSpace)
            for(;i<n&&((c=str.charAt(i))<'0'||c>'9');++i) ;
        lastSuccess=false;
        for(;i<n&&((c=str.charAt(i))>='0'&&c<='9');x=x*10+c-'0',++i,lastSuccess=true);
        return x;
    }

    public int nextInt(boolean ignoreFrontSpace)
    {
        char c=0;
        int x=0, f=1, n=str.length();
        if(i>=n) return 0;
        if(ignoreFrontSpace)
        {
            for(;i<n&&((c=str.charAt(i))<'0'||c>'9');++i)
            {
                if(str.charAt(i)=='+')
                    f=1;
                else if(str.charAt(i)=='-')
                    f=-1;
            }
        }
        else
        {
            if(str.charAt(i)=='+')
            {
                ++i;
                f=1;
            }
            else if(str.charAt(i)=='-')
            {
                ++i;
                f=-1;
            }
        }
        lastSuccess=false;
        for(;i<n&&((c=str.charAt(i))>='0'&&c<='9');x=x*10+c-'0',++i,lastSuccess=true) ;
        return x*f;
    }
    public double nextDouble(boolean ignoreFrontSpace)
    {
        double x=nextInt(ignoreFrontSpace);
        if(lastSuccess&&i<str.length()&&str.charAt(i)=='.')
        {
            ++i;
            int tmp_i=i;
            boolean ls=lastSuccess;
            int tmp=nextUnsignedInt(false);
            if(lastSuccess)
                x+=(x>=0?1:-1)*Math.pow(0.1,i-tmp_i)*tmp;
            lastSuccess=ls;
        }
        return x;
    }
    public double nextScience(boolean ignoreFrontSpace)
    {
        double x=nextDouble(ignoreFrontSpace);
        if(lastSuccess&&i<str.length()&&(str.charAt(i)=='e'||str.charAt(i)=='E'))
        {
            ++i;
            boolean ls=lastSuccess;
            int tmp=nextInt(false);
            if(lastSuccess)
                x*=Math.pow(10,tmp);
            lastSuccess=ls;
        }
        return x;
    }

    public char checkNextExpr()
    {
        char c=0;
        int x=0, f=1, n=str.length();
        String strs="01234567890-+e.*/()%=";
        for(;i<n;++i)
        {
            c=str.charAt(i);
            for(int j=0, m=strs.length();j<m;++j)
                if(strs.charAt(j)==c)
                    return c;
        }
        return ' ';
    }

    public char getNextExpr()
    {
        char c=0;
        int x=0, f=1, n=str.length();
        String strs="-+*/()%=";
        for(;i<n;++i)
        {
            c=str.charAt(i);
            for(int j=0, m=strs.length();j<m;++j)
                if(strs.charAt(j)==c)
                {
                    ++i;
                    return c;
                }
        }
        return ' ';
    }

    public boolean end()
    {
        return i==str.length();
    }
}
